<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="fns" uri="http://java.sun.com/jsp/jstl/functionss" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>用户管理</title>
    <jsp:include page="../body/link-page.jsp" flush="true"/>

</head>
<body>
<div class="panel">
    <form id="form" action="/org/list" method="post">

        <div class="panel-heading row">
            <div class="col-md-8">
                <button type="button" id="demo-dt-addrow-btn" class="btn btn-info" onclick="LAYER.addLayerWithSize('layer_orgAdd','添加','/org/add','800px','400px')">
                    <i class="fa fa-plus"></i> 添加
                </button>
                <button type="button" class="btn btn-success" onclick="toEdit();"><i class="fa fa-edit"></i> 修改</button>
                <button type="button" class="btn btn-warning" onclick="toAuth();"><i class="fa fa-thumb-tack"></i> 授权</button>
                <button type="button" class="btn btn-primary" onclick="deleteAllCheck();"><i class="fa fa-trash-o"></i> 删除</button>
            </div>
            <div class="col-md-4">
                <div class="input-group" style="text-align: right">
                    <div class="input-group-addon">
                        <span class="fa fa-search"></span>
                    </div>
                    <input type="text" name="search" id="search" class="form-control col-md-3" placeholder="搜索列表内容"/>
                    <div class="input-group-btn">
                        <button type="button" class="btn btn-primary btn-search">搜索</button>
                        <button type="button" class="btn btn-primary btn-resert" style="margin-left: 3px;">重置</button>
                    </div>
                </div>
            </div>

        </div>

        <div id="table-box" class="panel-body">
            <table id="table" class="table table-striped table-bordered dataTable no-footer dtr-inline" cellspacing="0" width="100%" role="grid" aria-describedby="demo-dt-addrow_info" style="width: 100%;" data-pn="${page.pageNum}" data-ps="${page.pageSize}" data-tp="${page.totalPage}" data-tr="${page.totalRecord}">
                <thead>
                <tr role="row">
                    <th style="width: 20px;"><input type="checkbox" id="check-all" /></th>
                    <th>组织名称</th>
                    <th>父组织名称</th>
                    <th>描述</th>
                    <th>创建时间</th>
                </tr>
                </thead>
                <tbody>
                <c:choose>
                    <c:when test="${not empty page.results}">
                        <c:forEach items="${page.results}" var="item" varStatus="vs">
                            <tr role="row" class="odd">
                                <td><input type="checkbox" value="${item.id}" /></td>
                                <td>${item.orgName}</td>
                                <c:choose>
                                    <c:when test="${item.pId == 0}">
                                        <td></td>
                                    </c:when>
                                    <c:otherwise>
                                        <td>${item.pName}</td>
                                    </c:otherwise>
                                </c:choose>
                                <td>${item.description}</td>
                                <td>${fns:dateToStringTime(item.createTime)}</td>
                            </tr>
                        </c:forEach>
                    </c:when>
                    <c:otherwise>
                        <tr role="row" class="odd">
                            <td colspan="10" style="text-align: center">暂无数据</td>
                        </tr>
                    </c:otherwise>
                </c:choose>
                </tbody>
            </table>
            <ul class="pagination"></ul>
        </div>
    </form>
</div>

<script type="text/javascript">
    function deleteAllCheck() {
        var ids = getAllCheck("form");
        if(ids.length == 0){
            layer.msg("至少选择一条数据");
        } else {
            layer.confirm("确定要删除" + ids.length + "条数据？",{title:"提示",btn:["确定","取消"]}, function(){
                $.ajax({
                    url:"/org/delete",
                    data:{"ids":ids.join(",")},
                    type:"post",
                    dataType:"json",
                    success:function(data){
                        if(data.success){
                            layer.msg(data.msg);
                            reloadPage();
                        } else {
                            layer.msg(data.msg);
                        }
                    }
                });
            })
        }
    }

    function toEdit(){
        var id = getAllCheck("form");
        if(id.length != 1){
            layer.msg("请选择一条数据");
        } else {
            LAYER.addLayerWithSize("layer_edit","修改","/org/edit?id="+id,"400px","400px");
        }
    }

    function toAuth(){
        var id = getAllCheck("form");
        if(id.length != 1){
            layer.msg("请选择一条数据");
        } else {
            $.ajax({
                url:"/org/havePowerOrNot",
                type:"POST",
                data:{"id":id[0]},
                dataType:"JSON",
                success:function(data){
                    if(data.success){
                        LAYER.addOrgMenuIframe("layer_orgMenu","授权","${ctx}/tag/checktreeselect?id="+id,"400px","400px");
                    } else {
                        layer.msg(data.msg);
                    }
                }
            });

        }
    }

</script>

</body>
<jsp:include page="../body/javascript-page.jsp" flush="true"/>
</html>
